home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1996 #6 / Amiga Plus CD - 1996 - No. 06.iso / pd / programmierung / proasm / routines / tasks.r < prev    next >
Text File  |  1980-02-03  |  7KB  |  376 lines

  1.     
  2. ;---;  tasks.r  ;--------------------------------------------------------------
  3. *
  4. *    ****    SOME NIFTY LITTLE ROUTINES FOR TASKS    ****
  5. *
  6. *    Author        Stefan Walter
  7. *    Version        1.00
  8. *    Last Revision    21.07.92
  9. *    Identifier    tsk_defined
  10. *    Prefix        tsk_    (task tricks)
  11. *                 ¯    ¯¯
  12. *    Functions    DoesTaskExist, GetTaskAddrs, FreeTaskAddrs
  13. *            (CreateTaskInfo)
  14. *
  15. *    Flags        tsk_CTITOO set 1 if info creation also needed
  16. *
  17. ;------------------------------------------------------------------------------
  18.  
  19. ;------------------
  20.     ifnd    tsk_defined
  21. tsk_defined    =1
  22.  
  23. ;------------------
  24. tsk_oldbase    equ __base
  25.     base    tsk_base
  26. tsk_base:
  27.  
  28.  
  29. ;------------------
  30.  
  31. ;------------------------------------------------------------------------------
  32. *
  33. * DoesTaskExist    Test if a task is still in any of the two lists or in the
  34. *        thistask field.
  35. *
  36. * INPUT:    a0    Task address
  37. *
  38. * RESULT:    ccr    EQ if not, NE if yes
  39. *
  40. * NOTE        This routine should be called under Forbid() to guarantee
  41. *        the result at the end! A Disable() is not neccessary (see
  42. *        FindTask in the autodocs).
  43. *
  44. ;------------------------------------------------------------------------------
  45.  
  46. ;------------------
  47. DoesTaskExist:
  48.  
  49. ;------------------
  50. ; Init everything.
  51. ;
  52. \start:    movem.l    d0/a1/a6,-(sp)
  53.     move.l    4.w,a6
  54.  
  55. ;------------------
  56. ; Check both lists and thistask.
  57. ;
  58. \look:    move.l    420(a6),d0        ;waiting
  59.     bsr.s    \test
  60.     move.l    406(a6),d0        ;ready
  61.     bsr.s    \test
  62.     cmp.l    $114(a6),a0        ;thistask
  63.     beq.s    \yes2
  64.  
  65. ;------------------
  66. ; Results...
  67. ;
  68. \no:    moveq    #0,d0
  69. \exit:    movem.l    (sp)+,d0/a1/a6
  70.     rts
  71.  
  72. \yes:    addq.l    #4,a7
  73. \yes2:    moveq    #-1,d0
  74.     bra.s    \exit
  75.  
  76. ;------------------
  77. ; Test subroutine.
  78. ;
  79. \test:    move.l    d0,a1
  80.     move.l    (a1),d0
  81.     beq.s    \done
  82.     cmp.l    a1,a0
  83.     bne.s    \test
  84.     bra.s    \yes
  85. \done:    rts
  86.  
  87.  
  88. ;------------------
  89.  
  90. ;------------------------------------------------------------------------------
  91. *
  92. * GetTaskAddrs    Smartly get the addresses of all task info blocks. Therefore a
  93. *        block of memory is allocated to contain all blocks.
  94. *
  95. * RESULT:    a0    Memory block
  96. *        d0    #of tasks or 0 if no memory available for memory
  97. *        ccr    On d0
  98. *
  99. * NOTE        When the caller reads out the fields, it should test if the
  100. *        task still exists with DoesTaskExist. There it also should test
  101. *        the state of the task!
  102. *
  103. ;------------------------------------------------------------------------------
  104.  
  105. ;------------------
  106. GetTaskAddrs:
  107.  
  108. ;------------------
  109. ; Init everything.
  110. ;
  111. \start:    movem.l    d1-d7/a1-a6,-(sp)
  112.     move.l    4.w,a6
  113.  
  114. ;------------------
  115. ; Now quickly count all tasks.
  116. ;
  117. \quick:    moveq    #-1,d7            ;both \count add 1 too much
  118.     jsr    -132(a6)        ;Forbid()
  119.     move.l    406(a6),d0        ;ready
  120.     bsr.s    \count
  121.     move.l    420(a6),d0        ;waiting
  122.     bsr.s    \count
  123.     bra.s    \alloc
  124.  
  125. \count:    move.l    d0,a1
  126.     addq.l    #1,d7
  127.     move.l    (a1),d0
  128.     bne.s    \count
  129.     rts
  130.  
  131. ;------------------
  132. ; Allocate a memory block large enough for all counters.
  133. ;
  134. \alloc:    move.l    d7,d0
  135.     lsl.l    #2,d0
  136.     moveq    #1,d1
  137.     jsr    -198(a6)        ;AllocMem
  138.     tst.l    d0
  139.     beq.s    \fail
  140.     move.l    d0,a5
  141.  
  142. ;------------------
  143. ; Get all tasks into the list. If their number has changed in the meantime,
  144. ; call FreeTaskAddrs and go to quickcount again.
  145. ;
  146. \in:    move.l    d7,d6
  147.     subq.l    #1,d6
  148.     move.l    a5,a4
  149.     move.l    406(a6),d0        ;ready
  150.     bsr.s    \fill
  151.     move.l    420(a6),d0        ;waiting
  152.     bsr.s    \fill
  153.     move.l    $114(a6),(a4)
  154.  
  155. ;------------------
  156. ; Results.
  157. ;
  158. \fine:    move.l    a5,a0
  159.     move.l    d7,d0
  160.  
  161. \exit:    jsr    -138(a6)        ;Permit()
  162.     tst.l    d0
  163.     movem.l    (sp)+,d1-d7/a1-a6
  164.     rts
  165.  
  166. \fail:    moveq    #0,d0
  167.     bra.s    \exit
  168.  
  169. ;------------------
  170. ; Fill in table.
  171. ;
  172. \fill:    move.l    d0,a1
  173.     move.l    (a1),d0
  174.     beq.s    \done
  175.     move.l    a1,(a4)+
  176.     bra.s    \fill
  177. \done:    rts
  178.  
  179.  
  180. ;------------------
  181.  
  182. ;------------------------------------------------------------------------------
  183. *
  184. * FreeTaskAddrs    Free the memory block generated by GetTaskAddrs.
  185. *
  186. * RESULT:    a0    Memory block
  187. *        d0    #of tasks
  188. *
  189. ;------------------------------------------------------------------------------
  190.  
  191. ;------------------
  192. FreeTaskAddrs
  193.  
  194. ;------------------
  195. ; Init everything.
  196. ;
  197. \start:    movem.l    d0-a6,-(sp)
  198.     move.l    4.w,a6
  199.     move.l    a0,a1
  200.     lsl.l    #2,d0
  201.     jsr    -210(a6)
  202.     movem.l    (sp)+,d0-a6
  203.     rts
  204.  
  205.  
  206. ;------------------
  207.     IFD    tsk_CTITOO
  208.  
  209. ;------------------
  210.  
  211. ;------------------------------------------------------------------------------
  212. *
  213. * CreateTaskInfo    Retrieve the standard information needed from a task
  214. *            and prepare them for DoRawFmt and Print.
  215. *
  216. * INPUT:    a0    Task
  217. *        a1    Buffer (80 bytes)
  218. *
  219. * RESULT    a0    Task
  220. *        a1    DoRawFmt buffer
  221. *        d0    0 if this task no longer exists, -1 if okay
  222. *        ccr    on d0
  223. *
  224. ;------------------------------------------------------------------------------
  225.  
  226. ;------------------
  227. CreateTaskInfo:
  228.  
  229. ;------------------
  230. ; Init everything.
  231. ;
  232. \start:    movem.l    d1-a6,-(sp)
  233.     move.l    4.w,a6
  234.     jsr    -132(a6)        ;Forbid()
  235.     lea    6*4(a1),a3
  236.  
  237. \exist:    bsr    DoesTaskExist
  238.     beq    \fail
  239.  
  240. \gadr:    move.l    a0,(a1)+        ;task address
  241.     lea    tsk_objnames(pc),a2
  242.     cmp.b    #13,8(a0)
  243.     seq    d6
  244.     bne.s    \gobj
  245.     addq.l    #8,a2
  246.  
  247. \gobj:    move.l    a2,(a1)+
  248.     moveq    #0,d0
  249.     move.b    15(a0),d0
  250.     cmp.b    #6,d0
  251.     bls.s    \gstat
  252.     moveq    #0,d0
  253.  
  254. \gstat:    mulu    #10,d0
  255.     pea    tsk_statenames(pc)
  256.     add.l    (sp)+,d0
  257.     move.l    d0,(a1)+
  258.  
  259. \spri:    move.b    9(a0),d0
  260.     ext.w    d0
  261.     ext.l    d0
  262.     move.l    d0,(a1)+
  263.     
  264. \gpri:    move.l    a3,(a1)+
  265.     move.l    #"---"*256,(a3)+
  266.     moveq    #0,d7
  267.     tst.b    d6
  268.     beq.s    \ncli
  269.     tst.l    $8c(a0)
  270.     beq.s    \ncli
  271.     moveq    #-1,d7
  272.     subq.l    #4,a3
  273.     movem.l    d0-a5,-(sp)
  274.     lea    $8c(a0),a1
  275.     lea    tsk_dectext(pc),a0
  276.     lea    \setin(pc),a2
  277.     jsr    -522(a6)        ;RawDoFmt()
  278.     movem.l    (sp)+,d0-a5
  279. \fz:    tst.b    (a3)+
  280.     bne.s    \fz
  281.     bra.s    \ncli
  282.  
  283. \setin:    move.b    d0,(a3)+
  284.     rts
  285.  
  286. \ncli:    move.l    a3,(a1)+
  287.     move.l    10(a0),a2
  288.     move.w    tsk_namelen(pc),d5    ;40 chars (-1 for 0)
  289.  
  290. \ct:    tst.b    (a2)
  291.     beq.s    \cted
  292.     move.b    (a2)+,d0
  293.     bsr.s    \pbyt
  294.     bra.s    \ct
  295.  
  296. \pbyt:    tst.b    d5
  297.     beq.s    \pbyte
  298.     cmp.b    #$d,d0
  299.     beq.s    \pbyte
  300.     cmp.b    #$a,d0
  301.     beq.s    \pbyte
  302.     subq.b    #1,d5
  303.     cmp.b    #$d,d0
  304.     beq.s    \pbyte
  305.     move.b    d0,(a3)+
  306. \pbyte:    rts
  307.  
  308. \cted:    tst.b    d7
  309.     beq.s    \gname
  310.     moveq    #" ",d0
  311.     bsr.s    \pbyt
  312.     moveq    #"[",d0
  313.     bsr.s    \pbyt
  314.     move.l    $ac(a0),d0
  315.     lsl.l    #2,d0
  316.     move.l    d0,a2
  317.     move.l    $10(a2),d0
  318.     lsl.l    #2,d0
  319.     move.l    d0,a2
  320.     move.b    (a2)+,d1
  321. \cc:    tst.b    d1
  322.     beq.s    \cced
  323.     subq.b    #1,d1
  324.     move.b    (a2)+,d0    
  325.     bsr.s    \pbyt
  326.     bra.s    \cc
  327.  
  328. \cced:    moveq    #"]",d0
  329.     bsr.s    \pbyt
  330. \gname:    clr.b    (a3)
  331.  
  332. \okay:    moveq    #-1,d0
  333. \exit:    jsr    -138(a6)        ;Permit()
  334.     tst.l    d0
  335.     movem.l    (sp)+,d1-a6
  336.     rts
  337.  
  338. \fail:    moveq    #0,d0
  339.     bra.s    \exit
  340.  
  341. ;------------------
  342.  
  343. ;--------------------------------------------------------------------
  344.  
  345. ;------------------
  346. tsk_statenames:    dc.b    "invalid  ",0
  347.         dc.b    "added    ",0
  348.         dc.b    "running  ",0
  349.         dc.b    "ready    ",0
  350.         dc.b    "waiting  ",0
  351.         dc.b    "exception",0
  352.         dc.b    "removed  ",0
  353.  
  354. tsk_objnames:    dc.b    "task   ",0
  355.         dc.b    "process",0
  356.  
  357. tsk_dectext:    dc.b    "%3ld",0
  358.         even
  359.  
  360. tsk_namelen:    dc.w    80        ;change by software
  361.  
  362. ;------------------
  363.     ENDIF
  364. ;------------------
  365.  
  366. ;--------------------------------------------------------------------
  367.  
  368. ;------------------
  369.     base    tsk_oldbase
  370.  
  371. ;------------------
  372.     endif
  373.  
  374.     end
  375.  
  376.